package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @GetMapping("/read/room/{roomId}")
    //@ApiOperation 用在方法上说明方法的作用和用途
    @ApiOperation(value = "根据房间id查询床位", notes = "传入房间id")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            //@ApiParam 用在方法参数上，描述单个形参的含义
            @ApiParam(value = "房间ID", required = true) @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }

    /**
     * 创建床位
     * @param bed
     * @return
     */
    @PostMapping("/create")
    @ApiOperation(value = "创建床位",notes="传入床位对应的id")
    public ResponseResult createBed(@RequestBody BedDto bed){
        bedService.createBed(bed);
        return ResponseResult.success();
    }

    /**
     * 根据id来查询床位
     * @param id
     * @return
     */
    @GetMapping("/read/{id}")
    @ApiOperation(value = "根据id来查询床位",notes ="传入的床位id")
    public ResponseResult readBed(@ApiParam(value ="床位id",readOnly = true) @PathVariable("id") Long id){
        BedVo bed= bedService.getBedById(id);
        return success(bed);
    }

    /**
     * 更改床位
     * @param bed
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "根据id来修改床位",notes = "传入的床位对象，包括床位id，床位号，所属的房间号等信息")
    public ResponseResult updateBed(@RequestBody BedDto bed){
        bedService.update(bed);
        return success();
    }

    /**
     * 删除床位
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除床位",notes = "传入的床位id")
    public ResponseResult deleteBed(@ApiParam(value = "床位的id" ,required = true) @PathVariable Long id){
        bedService.deleteBed(id);
        return success();
    }
}
